<template>
	<el-form label-width="140px" :model="form" :rules="rules" ref="queryForm">
		<el-row>
			<el-col :span="12">

				<el-form-item label="指挥所车辆名称" prop="name">
					<el-input v-model="form.name" style="width: 190px;"></el-input>
				</el-form-item>

				<el-form-item label="指挥所车辆编号" prop="code">
					<el-input v-model="form.code" style="width: 190px;"></el-input>
				</el-form-item>

				<el-form-item label="所属机动指挥所" prop="cfId">
					<el-select v-model="form.cfId" size="default" placeholder="请选择" style="width: 190px" clearable
						filterable>
						<el-option v-for="item in options" :key="item.id" :label="item.name" :value="item.id" />
					</el-select>
				</el-form-item>

				<el-form-item label="类型" prop="type">
					<el-select v-model="form.type" size="default" placeholder="请选择" style="width: 190px" clearable
						filterable>
						<el-option v-for="item in typeOptions" :key="item.dictValue" :label="item.dictLabel"
							:value="item.dictValue" />
					</el-select>
				</el-form-item>

				<el-form-item label="车牌号" prop="carNumber">
					<el-input v-model="form.carNumber" style="width: 190px;"></el-input>
				</el-form-item>

				<el-form-item label="车辆品牌" prop="brand">
					<el-input v-model="form.brand" style="width: 190px;"></el-input>
				</el-form-item>

				<el-form-item label="车辆型号" prop="model">
					<el-input v-model="form.model" style="width: 190px;"></el-input>
				</el-form-item>

				<el-form-item label="乘坐人数" prop="rideNumber">
					<el-input v-model="form.rideNumber" style="width: 190px;"
						@input="e => regOnlyNumSpot(e, form, 'rideNumber', 0)"></el-input>
				</el-form-item>

				<el-form-item label="车长" prop="length">
					<el-input v-model="form.length" style="width: 190px;"
						@input="e => regOnlyNumSpot(e, form, 'length', 2)"></el-input>
				</el-form-item>

				<el-form-item label="车宽" prop="width">
					<el-input v-model="form.width" style="width: 190px;"
						@input="e => regOnlyNumSpot(e, form, 'width', 2)"></el-input>
				</el-form-item>

				<el-form-item label="车高" prop="height">
					<el-input v-model="form.height" style="width: 190px;"
						@input="e => regOnlyNumSpot(e, form, 'height', 2)"></el-input>
				</el-form-item>


			</el-col>
			<el-col :span="12">

				<el-form-item label="车自重" prop="weight">
					<el-input v-model="form.weight" style="width: 190px;"
						@input="e => regOnlyNumSpot(e, form, 'weight', 2)"></el-input>
				</el-form-item>

				<el-form-item label="车载重" prop="load">
					<el-input v-model="form.load" style="width: 190px;"
						@input="e => regOnlyNumSpot(e, form, 'load', 2)"></el-input>
				</el-form-item>

				<el-form-item label="最高时速" prop="speed">
					<el-input v-model="form.speed" style="width: 190px;"
						@input="e => regOnlyNumSpot(e, form, 'speed', 2)"></el-input>
				</el-form-item>

				<el-form-item label="最长行驶距离" prop="distance">
					<el-input v-model="form.distance" style="width: 190px;"
						@input="e => regOnlyNumSpot(e, form, 'distance', 2)"></el-input>
				</el-form-item>

				<el-form-item label="最长行作业时间" prop="workingTime">
					<el-input v-model="form.workingTime" style="width: 190px;"
						@input="e => regOnlyNumSpot(e, form, 'workingTime', 2)"></el-input>
				</el-form-item>

				<el-form-item label="指挥控制手段" prop="comControl">
					<el-input v-model="form.comControl" style="width: 190px;"></el-input>
				</el-form-item>


				<el-form-item label="连接通信网络" prop="communicationNetwork">
					<el-input v-model="form.communicationNetwork" style="width: 190px;"></el-input>
				</el-form-item>


				<el-form-item label="通信手段" prop="communicationMeans">
					<el-input v-model="form.communicationMeans" style="width: 190px;"></el-input>
				</el-form-item>

				<el-form-item label="联系人" prop="contact">
					<el-input v-model="form.contact" style="width: 190px;"></el-input>
				</el-form-item>

				<el-form-item label="联系电话" prop="contactNumber">
					<el-input v-model="form.contactNumber" style="width: 190px;"
						@input="e => regOnlyNumSpot(e, form, 'contactNumber', 0)" maxlength="11"></el-input>
				</el-form-item>

			</el-col>
		</el-row>

		<div style="display: flex;justify-content: flex-end;">
			<el-button @click="closethis()" @keyup.prevent @keydown.enter.prevent>取消</el-button>
			<el-button type="primary" @click="submit(queryForm)" @keyup.prevent @keydown.enter.prevent>确定</el-button>
		</div>
	</el-form>
</template>

<script setup>
	import {
		ref,
		reactive,
		onMounted
	} from 'vue'
	import {
		ElMessage
	} from 'element-plus'

	import {
		commonInterface
	} from '@/api/common/common'

	import {
		regOnlyNumSpot
	} from '@/utils/reg'

	const emit = defineEmits(['getList', 'closeWindow'])
	const props = defineProps(['editData', 'options', 'typeOptions'])

	const form = ref({})

	const queryForm = ref('')

	const typeOptions = ref()
	const options = ref()

	//必填项
	const rules = reactive({

		name: [{
			required: true,
			message: "此选项不能为空!",
			trigger: "blur"
		}]


	})
	//取消
	const closethis = () => {
		emit('closeWindow')
	}

	//确定
	const submit = async (e) => {
		if (!e) return
		await e.validate((valid) => {
			if (valid) {
				let method = 'post'
				if (props.editData) method = 'put'
				commonInterface('/back/renfang/zhtx/cara/', form.value, method).then(result => {
					if (result.code === 200) {
						ElMessage.success(result.msg)
						emit('closeWindow')
						emit('getList')
					} else {
						ElMessage.error(result.msg)
					}
				})
			}
		})
	}

	onMounted(() => {
		typeOptions.value = props.typeOptions
		options.value = props.options
		if (props.editData) form.value = props.editData
	})
</script>

<style>
</style>